#!/usr/bin/python

from google.appengine.datastore import entity_pb

def decode_value(value_infos):
    value_type = ""
    value_val = ""
    if value_infos.has_int64value():
        value_type = "int64"
        value_val = value_infos.int64value()
    if value_infos.has_stringvalue():
        value_type = "string"
        value_val = value_infos.stringvalue()
    if value_infos.has_booleanvalue():
        alue_type = "boolean"
        value_val = value_infos.booleanvalue()
    if value_infos.has_doublevalue():
        value_type = "double"
        value_val = value_infos.doublevalue()
    if value_infos.has_pointvalue():
        value_type = "point"
        point_infos = value_infos.pointvalue()
        value_val = [point_infos.x(), point_infos.y()]
    if value_infos.has_uservalue():
        value_type = "user"
        user_infos = value_infos.uservalue()
        value_val = {}
        if user_infos.has_email():
            value_val['email'] = user_infos.email()
        if user_infos.has_auth_domain():
            value_val['auth_domain'] = user_infos.auth_domain()
        if user_infos.has_nickname():
            value_val['nickname'] = user_infos.nickname()
        if user_infos.has_gaiaid():
            value_val['gaiaid'] = user_infos.gaiaid()
        if user_infos.has_obfuscated_gaiaid():
            value_val['obfuscated_gaiaid'] = user_infos.obfuscated_gaiaid()
    if value_infos.has_referencevalue():
        value_type = "reference"
        value_val = value_infos.referencevalue()
	print '******* reference value *******'
   	print 'reference value: ' + str(value_val)
        print '***** app: ' + value_val.app()
	print '***** name space: ' + value_val.name_space()
	print '***** pathelement: '
        for item in value_val.pathelement_list():
	    print item.type()
	    print item.id()
	    print item.name()
	print '******* end value *******'
    return value_type, value_val

